var t = require("../../@babel/runtime/helpers/objectSpread2"), a = require("../../@babel/runtime/helpers/defineProperty"), e = getApp(), s = [ {
    name: "推荐商品",
    show: !0
}, {
    name: "新品上市",
    show: !0
}, {
    name: "热卖商品",
    show: !0
}, {
    name: "促销商品",
    show: !0
}, {
    name: "限时抢购",
    show: !0
} ], i = {
    goback: function() {
        wx.navigateBack();
    },
    getJson: function(t) {
        var a = this.data, e = a.image_url, s = a.order_field, i = a.order_by, n = a.brandId, r = a.typestring, o = a.filterId, d = a.attrstr, c = {
            image_url: e,
            page: t + 1,
            order_field: s,
            order_by: i
        };
        return n && (c["search[brand_id]"] = n), d && d.length > 0 && (c["search[product_attr]"] = d.toString()), 
        o && o.length > 0 && (c["search[filtering]"] = o.toString()), r && (c["search[category]"] = r), 
        c;
    },
    initData: function() {
        this.setData({
            page: 0,
            goods: [],
            noMore: !1
        });
    },
    getdata: function() {
        this.initData(), this.getGoods();
    },
    getMoreData: function() {
        if (this.data.noMore) return e.tips("没有更多了");
        this.getGoods();
    },
    getGoods: function() {
        var t = this;
        if (wx.showLoading({
            title: "加载中"
        }), this.data.loading) return !1;
        this.setData({
            loading: !0
        });
        var a = this.getJson(this.data.page), s = e.getNetAddresss("plugin.scan-picture.frontend.modules.goods.controllers.search.index");
        e._postNetWork({
            url: s,
            data: a,
            success: function(s) {
                var i = s.data, n = i.result, r = i.msg, o = i.data.goods_list;
                if (wx.hideLoading(), t.setData({
                    loading: !1
                }), n) {
                    var d = t.data, c = d.goods, l = d.page;
                    c = c.concat(o.data), t.setData({
                        noMore: l == o.last_page,
                        goods: c,
                        page: a.page
                    });
                } else e.tips(r);
            },
            fail: function(a) {
                wx.hideLoading(), t.setData({
                    loading: !0
                });
            }
        });
    },
    toggle: function(t) {
        var a = t.currentTarget.dataset.val, e = "asc" == this.data.order_by ? "desc" : "asc";
        this.setData({
            order_by: e,
            order_field: a
        }), this.getdata();
    },
    showbox: function() {
        this.setData({
            show: !this.data.show
        });
    }
}, n = {
    data: {
        screentitle: [ "品牌", "分类", "属性", "高级选项" ],
        select: "",
        brand: {},
        activeName: "1",
        classification1: [],
        classificationkey: "0",
        classificationId: null,
        classificationId1: null,
        classificationId2: null,
        classificationParentIndex: 0,
        typestring: "",
        attr: s,
        attrstr: [],
        attrkey: [],
        tagname: [],
        filterId: [],
        showtagnamekey: null
    },
    methods: {
        changetype: function(t) {
            var a = t.currentTarget.dataset.key;
            switch (this.setData({
                select: a
            }), this.resetselect(), a) {
              case 0:
                this.setData({
                    show1: !0
                });
                break;

              case 1:
                this.setData({
                    show2: !0
                });
                break;

              case 2:
                this.setData({
                    show3: !0
                });
                break;

              case 3:
                this.setData({
                    show4: !0
                });
            }
        },
        getbrand: function() {
            var t = this, a = e.getNetAddresss("goods.brand.get-brand");
            e._postNetWork({
                url: a,
                showToastIn: !1,
                data: {},
                success: function(a) {
                    var e = a.data, s = e.result, i = e.data;
                    1 == s && t.setData({
                        brand: i.data
                    });
                }
            });
        },
        screenbrand: function(t) {
            var a = t.currentTarget.dataset.id;
            this.setData({
                brandId: a
            }), this.getdata(), this.showbox();
        },
        onChange: function(t) {
            var a = t.detail;
            this.setData({
                activeName: a
            });
        },
        getclassification: function() {
            var t = this, a = e.getNetAddresss("goods.category.search-goods-category");
            e._getNetWork({
                showToastIn: !1,
                url: a,
                success: function(a) {
                    var e = a.data, s = e.result, i = e.data;
                    1 == s && t.setData({
                        classification1: i
                    });
                }
            });
        },
        classificationtype: function(t) {
            var a = t.currentTarget.dataset, e = a.id, s = a.key;
            this.setData({
                classification2: [],
                typestring: e,
                classificationkey: s
            }), this.data.classificationId != e ? (this.setData({
                classificationId: e
            }), this.setData({
                classificationId1: null,
                classificationId2: null,
                classificationshow: !1
            })) : this.setData({
                classificationId: null
            });
        },
        classificationtype1: function(t) {
            var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.parentIndex;
            this.setData({
                typestring: a,
                classificationParentIndex: e,
                classificationshow: !0
            }), this.data.classificationId1 == a ? this.setData({
                classificationId1: null
            }) : this.setData({
                classificationId1: a
            }), this.setData({
                classificationId2: null
            });
        },
        classificationtype2: function(t) {
            var a = t.currentTarget.dataset.id;
            this.data.typestring == a ? this.setData({
                typestring: null
            }) : this.setData({
                typestring: a
            }), this.data.classificationId2 == a ? this.setData({
                classificationId2: null
            }) : this.setData({
                classificationId2: a
            });
        },
        selectattr: function(t) {
            var e = t.currentTarget.dataset.key;
            switch (console.log(e), e) {
              case 0:
                this.findstr("is_recommand", e);
                break;

              case 1:
                this.findstr("is_new", e);
                break;

              case 2:
                this.findstr("is_hot", e);
                break;

              case 3:
                this.findstr("is_discount", e);
                break;

              case 4:
                this.findstr("limit_buy", e);
            }
            this.data.attr[e].show ? this.setData(a({}, "attr[" + e + "].show", !1)) : this.setData(a({}, "attr[" + e + "].show", !0));
        },
        findstr: function(t, a) {
            var e = this.data, s = e.attrstr, i = e.attrkey, n = s.indexOf(t);
            n > -1 ? (s.splice(n, 1), i.splice(n, 1)) : (s.push(t), i.push(a)), this.setData({
                attrstr: s,
                attrkey: i
            });
        },
        getname: function() {
            var t = this, a = e.getNetAddresss("goods.filtering.index");
            e._getNetWork({
                showToastIn: !1,
                url: a,
                success: function(a) {
                    var e = a.data, s = e.result, i = e.data;
                    if (1 == s) {
                        for (var n = 0; n < i.length; n++) for (var r = 0; r < i[n].value.length; r++) t.data.filterId.includes(i[n].value[r].id) ? i[n].value[r].record = 2 : i[n].value[r].record = 1;
                        t.setData({
                            tagname: i
                        });
                    }
                }
            });
        },
        showtagname: function(t) {
            var a = t.currentTarget.dataset.key;
            a != this.data.showtagnamekey ? this.setData({
                showtagnamekey: a
            }) : this.setData({
                showtagnamekey: null
            });
        },
        selectname: function(t) {
            var e = t.currentTarget.dataset, s = e.id, i = e.key, n = e.keyx;
            if (1 == this.data.tagname[i].value[n].record) {
                if (this.data.filterId.includes(s)) return;
                var r = this.data.filterId;
                r.push(s), this.setData({
                    filterId: r
                }), this.setData(a({}, "tagname.[" + i + "].value[" + n + "].record", 2));
            } else {
                var o = this.data.filterId.indexOf(s), d = this.data.filterId;
                d.splice(o, 1), this.setData({
                    filterId: d
                }), this.setData(a({}, "tagname.[" + i + "].value[" + n + "].record", 1));
            }
        },
        screen: function() {
            this.getdata(), this.showbox();
        },
        resetnames: function() {
            this.setData({
                namestring: null,
                showtagnamekey: null,
                namekey: null,
                brandId: "",
                attrstr: [],
                filterId: [],
                attrkey: [],
                typestring: "",
                classificationkey: null,
                classificationkey1: null,
                classificationkey2: null,
                attr: s
            });
            for (var t = 0; t < this.data.tagname.length; t++) for (var e = 0; e < this.data.tagname[t].value.length; e++) 2 == this.data.tagname[t].value[e].record && this.setData(a({}, "tagname.[" + t + "].value[" + e + "].record", 1));
        }
    }
};

Page(t(t(t({
    data: t({
        image_url: "",
        goods: [],
        page: 0,
        isLoading: !1,
        loading: !1,
        noMore: !1,
        goods_template: {
            names: "04",
            type: "goodsList"
        },
        order_by: "",
        order_field: "",
        sortList: [ {
            name: "评价",
            val: "comment_num"
        }, {
            name: "销量",
            val: "show_sales"
        }, {
            name: "价格",
            val: "price"
        } ],
        show: !1
    }, n.data),
    onLoad: function(t) {
        var a = t.url;
        this.setData({
            image_url: a
        }), a ? (this.getdata(), this.getbrand(), this.getclassification(), this.getname()) : this.goback();
    }
}, i), n.methods), {}, {
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getMoreData();
    },
    onShareAppMessage: function() {}
}));